package com.example.g7640.controller;


import com.example.g7640.builder.ResultBuilder;
import com.example.g7640.dto.CustomerDto;
import com.example.g7640.dto.VendorDto;
import com.example.g7640.dto.VendorQuery;
import com.example.g7640.dto.VendorResult;
import com.example.g7640.dto.common.PageResult;
import com.example.g7640.dto.common.Result;
import com.example.g7640.service.VendorService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author  
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/api/vendor")
public class VendorController {


    @Resource
    VendorService vendorService;

    @PostMapping("/set-password")
    public Result<String> resetPassword(@RequestBody VendorDto vendorDto){
        vendorService.resetPassword(vendorDto);
        return ResultBuilder.buildSuccess(null);
    }

    @GetMapping("/get-list")
    public PageResult<List<VendorResult>> getList(VendorQuery query){
        return vendorService.query(query);
    }

    @GetMapping("/get-info")
    public Result<VendorResult> getInfo(Integer id){
        return ResultBuilder.buildSuccess(vendorService.getInfo(id));
    }

    @PostMapping("/update-args")
    public Result<String> update(@RequestBody VendorDto vendorDto){
        vendorService.update(vendorDto);
        return ResultBuilder.buildSuccess();
    }


    @PostMapping("/add")
    public Result<String> add(@RequestBody VendorDto vendorDto){
        vendorService.add(vendorDto);
        return ResultBuilder.buildSuccess();
    }

    @GetMapping("/del")
    public Result<String> delete(Integer id){
        vendorService.delete(id);
        return ResultBuilder.buildSuccess();
    }

}
